package com.haidechizi.leetcode;

public class _466_统计重复个数 {

    public int getMaxRepetitions(String s1, int n1, String s2, int n2) {
        int i = 0;
        int i1 = 0;
        int i2 = 0;
        int m = 0;
        char[] chars1 = s1.toCharArray();
        char[] chars2 = s2.toCharArray();
        while (i < chars1.length * n1) {
            if (i1 == chars1.length) {
                i1 = 0;
            }
            if (i2 == chars2.length) {
                i2 = 0;
                m++;
            }
            if (chars1[i1] == chars2[i2]) {
                i2++;
            }
            i1++;
            i++;
        }
        if (i1 == chars1.length && i2 == chars2.length) {
            m++;
        }
        return m / n2;

    }


    public int getMaxRepetitions1(String s1, int n1, String s2, int n2) {
        int i1 = 0;
        int i2 = 0;
        int m = 0;
        char[] chars1 = generateStr(s1, n1).toCharArray();
        char[] chars2 = generateStr(s2, n2).toCharArray();
        while (i1 < chars1.length) {
            if (i2 == chars2.length) {
                i2 = 0;
                m++;
            }
            if (chars1[i1] == chars2[i2]) {
                i2++;
            }
            i1++;
        }
        if (i1 == chars1.length && i2 == chars2.length) {
            m++;
        }
        return m;

    }

    public String generateStr(String s, int n) {
        StringBuilder sb = new StringBuilder();
        while (n > 0) {
            sb.append(s);
            n--;
        }
        return sb.toString();
    }


}
